<?php session_start();
require '../common/Utility.php';
require '../db/configuration.php';
require '../crud/CustomSecurity.class.php';
require '../crud/Users.class.php';
loadDB();
isAdmin();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../css/page.css" />
<link rel="stylesheet" type="text/css" href="../css/userAdmin.css" />
<title>User Admin</title>
<meta name="author" content="Димитър Гьормов">
</head>

<body>
<a class="lenta" href="index.php"> Начало </a>
<div id="main">
<?php

$crud = new Users(con());

if(isset($_POST['Remove'])) {
	$crud->remove($_POST['id']);
}

listUsers($crud);

function listUsers($crud){
	$table = $crud->getAll();
	echo '<p>  Users </p>';
	echo '<table>';
	echo '<tr>';
	echo '<td class="bold">';
	echo 'user';
	echo '</td>';
	echo '</tr>';
	foreach($table as $line){
		echo '<tr>';
		echo '<td>';
		echo maskEmail($line[0]);
		echo '</td>';
		echo '</tr>';
	}
	echo '</table>';
}


?>
<?php
function maskEmail($email) {
  $maskedEmail = '';
  $index = stripos($email,'@');
  for ($j = 0; $j < strlen($email); $j++) {
  	if ($j > $index && strcasecmp(substr($email, $j, 1), ".") != 0){
  		$maskedEmail.= 'x';
  	} else {
  		$maskedEmail.= substr($email, $j, 1);
  	}
  }
  return $maskedEmail;
}
?>


</div>
</body>
</html>
